package lab03.test09;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Client {
    public static void main(String[] args) {

        //单步调试

        List<Book> books = new ArrayList<>();
        String path = "D:\\旅院\\作业\\java\\3.txt";
        String path1="D:\\旅院\\作业\\java\\4.txt";

        BufferedReader reader = null;
        BufferedWriter writer = null;
        try {
            reader = new BufferedReader(new FileReader(path));
            String line = "";
            if ((line = reader.readLine()) != null) {

                String[] tokens = line.split("\t");

                Book book = new Book();
                book.bookNo = Integer.parseInt(tokens[0]);
                book.bookName = tokens[1];
                book.version = tokens[2];
                book.price = Double.parseDouble(tokens[3]);
                book.sales = Double.parseDouble(tokens[4]);

                books.add(book);

            }

            int i = 0;
            for (Book b : books) {
                if (i == 3) {
                    b.price = b.price + 20;
                }
                if (i == 4) {
                    b.price = b.price + 30;
                }
                i++;
            }

            writer = new BufferedWriter(new FileWriter(path1));
            for (Book b1 : books) {
                writer.write(b1.bookName + b1.bookNo+b1.version+b1.sales+b1.price);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    }
}
